Refactor STDP and event ops for new brainevent binary backend#817
Refactor STDP and event ops for new brainevent binary backend#817chaoming0625 merged 1 commit intomasterfrom
Conversation
…refactor event handling
Reviewer's GuideUpdates STDP weight update functions to new binary-specific APIs, migrates brainevent event structures and JIT connectivity operators to their newer Binary/JITCScalar variants, adjusts numpy compatibility and packaging metadata, and refreshes state module docs and requirements to match the new brainevent release. Sequence diagram for event_mv_prob_homo using BinaryArray and JITCScalarRsequenceDiagram
participant Caller
participant BrainPyMath as brainpy_math_event_matvec
participant BrainEvent as brainevent
participant Backend as array_backend
Caller->>BrainPyMath: event_mv_prob_homo(events, weight, conn_prob, seed, shape, outdim_parallel, transpose)
BrainPyMath->>BrainPyMath: unwrap Array wrappers
BrainPyMath->>BrainEvent: BinaryArray(events)
BrainEvent-->>BrainPyMath: binary_events
BrainPyMath->>BrainEvent: JITCScalarR((weight, conn_prob, seed), shape, corder)
BrainEvent-->>BrainPyMath: csr_operator
alt transpose_true
BrainPyMath->>Backend: vector @ csr_operator.T
Backend-->>Caller: result
else transpose_false
BrainPyMath->>Backend: vector @ csr_operator
Backend-->>Caller: result
end
Class diagram for updated STDP layers using binary weight update functionsclassDiagram
class Layer
class SupportSTDP {
+stdp_update(on_pre, on_post, w_min, w_max)
}
class Dense {
+W
+stdp_update(on_pre, on_post, w_min, w_max)
}
class Linear {
}
class DenseWeightLayer {
+weight
+stdp_update(on_pre, on_post, w_min, w_max)
}
class OneToOne {
+weight
+stdp_update(on_pre, on_post, w_min, w_max)
}
class CSRLayer {
+weight
+indices
+indptr
+_pre_ids
+_post_indptr
+w_indices
+stdp_update(on_pre, on_post, w_min, w_max)
}
class STDPUpdateFunctions {
+update_dense_on_binary_pre(weight, spike, trace, w_min, w_max)
+update_dense_on_binary_post(weight, trace, spike, w_min, w_max)
+update_csr_on_binary_pre(weight, indices, indptr, spike, trace, w_min, w_max, shape)
+update_csr_on_binary_post(weight, pre_ids, post_indptr, w_indices, trace, spike, w_min, w_max, shape)
}
Layer <|-- Dense
Layer <|-- DenseWeightLayer
Layer <|-- OneToOne
Layer <|-- CSRLayer
SupportSTDP <|.. Dense
SupportSTDP <|.. DenseWeightLayer
SupportSTDP <|.. OneToOne
SupportSTDP <|.. CSRLayer
Dense <|-- Linear
Dense ..> STDPUpdateFunctions : uses
DenseWeightLayer ..> STDPUpdateFunctions : uses
OneToOne ..> STDPUpdateFunctions : uses
CSRLayer ..> STDPUpdateFunctions : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@sourcery-ai title |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
if __name__ == '__main__':block inbrainpy/state/__init__.pyintroduces side-effectful debug printing in a package__init__module and should be removed to keep imports clean and predictable. - In
brainpy/state/README.mdthe install command was changed topip install brainpy.state -U, but PyPI packages cannot contain dots in their name, so this likely should remainbrainpy_state(or whatever the actual distribution name is). - The encoding declaration in
brainpy/initialize/base.pywas moved below the license header, which makes it ineffective per PEP 263; either move# -*- coding: utf-8 -*-back to the first or second line or remove it entirely if using UTF-8 by default.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `if __name__ == '__main__':` block in `brainpy/state/__init__.py` introduces side-effectful debug printing in a package `__init__` module and should be removed to keep imports clean and predictable.
- In `brainpy/state/README.md` the install command was changed to `pip install brainpy.state -U`, but PyPI packages cannot contain dots in their name, so this likely should remain `brainpy_state` (or whatever the actual distribution name is).
- The encoding declaration in `brainpy/initialize/base.py` was moved below the license header, which makes it ineffective per PEP 263; either move `# -*- coding: utf-8 -*-` back to the first or second line or remove it entirely if using UTF-8 by default.
## Individual Comments
### Comment 1
<location path="brainpy/state/README.md" line_range="40" />
<code_context>
```bash
-pip install brainpy_state -U
+pip install brainpy.state -U
```
</code_context>
<issue_to_address>
**issue (bug_risk):** The `pip install brainpy.state` command may be incorrect; consider confirming the actual package name on PyPI.
Because this is user-facing install guidance, an incorrect distribution name will lead to failed installs. Please verify the actual PyPI package name (e.g., whether it should be `brainpy_state` or another valid name) and update the command accordingly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| ```bash | ||
| pip install brainpy_state -U | ||
| pip install brainpy.state -U |
There was a problem hiding this comment.
issue (bug_risk): The pip install brainpy.state command may be incorrect; consider confirming the actual package name on PyPI.
Because this is user-facing install guidance, an incorrect distribution name will lead to failed installs. Please verify the actual PyPI package name (e.g., whether it should be brainpy_state or another valid name) and update the command accordingly.
|
@sourcery-ai title |
Summary by Sourcery
Update event-based computation and STDP weight update implementations to use new binary/event abstractions and aligned brainevent backends, while adjusting dependencies and minor docs.
Bug Fixes:
Enhancements:
Build:
Documentation: